// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PATIENT_OML_O39 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("6 PID",6)]
  	    [HL7Field(HL7Version.v27, 6, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("7 PD1",7)]
  	    [HL7Field(HL7Version.v27, 7, HL7Repeat.False, HL7Required.False,"PD1")]
	    public PD1 PD1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 PRT",8)]
  	    [HL7Field(HL7Version.v27, 8, HL7Repeat.True, HL7Required.False,"PRT")]
	    public PRT[] PRT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 NTE",9)]
  	    [HL7Field(HL7Version.v27, 9, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("10 NK1",10)]
  	    [HL7Field(HL7Version.v27, 10, HL7Repeat.True, HL7Required.False,"NK1")]
	    public NK1[] NK1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 PATIENT_VISIT",11)]
  	    [HL7Field(HL7Version.v27, 11, HL7Repeat.False, HL7Required.False,"PATIENT_VISIT_OML_O39")]
	    public PATIENT_VISIT_OML_O39 PATIENT_VISIT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("16 INSURANCE",16)]
  	    [HL7Field(HL7Version.v27, 16, HL7Repeat.True, HL7Required.False,"INSURANCE_OML_O39")]
	    public INSURANCE_OML_O39[] INSURANCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("21 GT1",21)]
  	    [HL7Field(HL7Version.v27, 21, HL7Repeat.False, HL7Required.False,"GT1")]
	    public GT1 GT1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("22 AL1",22)]
  	    [HL7Field(HL7Version.v27, 22, HL7Repeat.True, HL7Required.False,"AL1")]
	    public AL1[] AL1 {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
			PRT = PopSegmentParseAndCheckRequiredArray<PRT>(availableData, options, "PRT");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
			PATIENT_VISIT = ProcessGroup<PATIENT_VISIT_OML_O39>(availableData, options, "PATIENT_VISIT");
			INSURANCE = ProcessGroupArray<INSURANCE_OML_O39>(availableData, options, "INSURANCE");
			GT1 = PopSegmentParseAndCheckRequired<GT1>(availableData, options, "GT1");
			AL1 = PopSegmentParseAndCheckRequiredArray<AL1>(availableData, options, "AL1");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			bool isPD1 = availableData.StartsWith("PD1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PD1", options.Version) || isPD1) {
				return isPD1;
			}
			bool isPRT = availableData.StartsWith("PRT", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PRT", options.Version) || isPRT) {
				return isPRT;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			bool isNK1 = availableData.StartsWith("NK1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NK1", options.Version) || isNK1) {
				return isNK1;
			}
			PATIENT_VISIT_OML_O39 testPATIENT_VISIT_OML_O39 = new PATIENT_VISIT_OML_O39();
			bool grpCCPATIENT_VISIT_OML_O39 = (testPATIENT_VISIT_OML_O39.CanConsume(availableData, options));
			if (IsRequired("PATIENT_VISIT", options.Version) || grpCCPATIENT_VISIT_OML_O39) {
				return grpCCPATIENT_VISIT_OML_O39;
			}
			INSURANCE_OML_O39 testINSURANCE_OML_O39 = new INSURANCE_OML_O39();
			bool grpCCINSURANCE_OML_O39 = (testINSURANCE_OML_O39.CanConsume(availableData, options));
			if (IsRequired("INSURANCE", options.Version) || grpCCINSURANCE_OML_O39) {
				return grpCCINSURANCE_OML_O39;
			}
			bool isGT1 = availableData.StartsWith("GT1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("GT1", options.Version) || isGT1) {
				return isGT1;
			}
			bool isAL1 = availableData.StartsWith("AL1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("AL1", options.Version) || isAL1) {
				return isAL1;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PATIENT";
			}
        }

        static PATIENT_OML_O39() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PATIENT_OML_O39));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PD1 != null) {
			string segmentValue = PD1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PRT != null && PRT.Length > 0) {
			for (int i = 0; i < PRT.Length; i++) {
				string segmentValue = PRT[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (NK1 != null && NK1.Length > 0) {
			for (int i = 0; i < NK1.Length; i++) {
				string segmentValue = NK1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PATIENT_VISIT != null) {
			string segmentValue = PATIENT_VISIT.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (INSURANCE != null && INSURANCE.Length > 0) {
			for (int i = 0; i < INSURANCE.Length; i++) {
				string segmentValue = INSURANCE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (GT1 != null) {
			string segmentValue = GT1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (AL1 != null && AL1.Length > 0) {
			for (int i = 0; i < AL1.Length; i++) {
				string segmentValue = AL1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

